﻿namespace TetrisProject
{
    using System;

    using TetrisProject.Interfaces;
    using TetrisProject.GameObjects.Blocks;

    public class BlockFactory : IBlockFactory
    {
        private int width;
        private Random random;
        
        public BlockFactory(int width)
        {
            this.width = width - 4;
            this.random = new Random();
        }

        public GameObjects.GameObject CreateBlock()
        {
            switch (this.random.Next(7))
            {
                case 0:
                    return this.CreateBlockI();
                case 1:
                    return this.CreateBlockL();
                case 2:
                    return this.CreateBlockJ();
                case 3:
                    return this.CreateBlockS();
                case 4:
                    return this.CreateBlockZ();
                case 5:
                    return this.CreateBlockO();
                case 6:
                    return this.CreateBlockT();
                default:
                    return null;
            }
        }

        public BlockI CreateBlockI()
        {
            int coordY = this.random.Next(this.width);
            return new BlockI(coordY);
        }

        public BlockL CreateBlockL()
        {
            int coordY = this.random.Next(this.width);
            return new BlockL(coordY);
        }

        public BlockJ CreateBlockJ()
        {
            int coordY = this.random.Next(this.width);
            return new BlockJ(coordY);
        }

        public BlockO CreateBlockO()
        {
            int coordY = this.random.Next(this.width);
            return new BlockO(coordY);
        }

        public BlockT CreateBlockT()
        {
            int coordY = this.random.Next(this.width);
            return new BlockT(coordY);
        }

        public BlockZ CreateBlockZ()
        {
            int coordY = this.random.Next(this.width);
            return new BlockZ(coordY);
        }

        public BlockS CreateBlockS()
        {
            int coordY = this.random.Next(this.width);
            return new BlockS(coordY);
        }
    }
}
